package avicit.bdp.oss.dto;

import avicit.bdp.common.base.BaseDTO;
import avicit.bdp.oss.utils.stats.Capacity;
import avicit.platform6.core.annotation.log.FieldRemark;
import avicit.platform6.core.annotation.log.Id;
import avicit.platform6.core.annotation.log.LogField;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.multipart.MultipartFile;

import javax.persistence.Column;
import javax.persistence.Table;
import javax.persistence.Transient;

/**
 * @金航数码科技有限责任公司
 * @作者：developer
 * @邮箱：developer@avic-digital.com
 * @创建时间： 2020-11-12
 * @类说明：ObjectDto
 * @修改记录：
 * @注意事项：
 * @主要功能：对象Entity
 */
@ApiModel(value = "ObjectDto", description = "bdp_oss_object")
@Table(name = "bdp_oss_object")
public class ObjectDto extends BaseDTO {
    private static final long serialVersionUID = 1L;

    /**
     * 主键
     */
    @Id
    @LogField
    @ApiModelProperty(value = "主键")
    @FieldRemark(column = "id", field = "id", name = "id")
    @javax.persistence.Id
    @Column(name = "id")
    private String id;

    /**
     * 对象名称
     */
    @LogField
    @ApiModelProperty(value = "对象名称")
    @FieldRemark(column = "object_name", field = "object_name", name = "对象名称")
    @Column(name = "object_name")
    private String objectName;

    /**
     * 对象大小
     */
    @LogField
    @ApiModelProperty(value = "对象大小，此处用String类型，Minio最大支持5TB，long不满足要求")
    @FieldRemark(column = "object_size", field = "object_size", name = "对象大小")
    @Column(name = "object_size")
    private long objectSize;

    /**
     * 对象前缀
     */
    @LogField
    @ApiModelProperty(value = "对象前缀")
    @FieldRemark(column = "prefix", field = "prefix", name = "对象前缀")
    @Column(name = "prefix")
    private String prefix;

    /**
     * 桶名称
     */
    @LogField
    @ApiModelProperty(value = "桶名称")
    @FieldRemark(column = "bucket_name", field = "bucket_name", name = "桶名称")
    @Column(name = "bucket_name")
    private String bucketName;

    /**
     * 目录标识
     */
    @LogField
    @ApiModelProperty(value = "目录标识")
    @FieldRemark(column = "is_directory", field = "is_directory", name = "目录标识")
    @Column(name = "is_directory")
    private boolean isDirectory;

    /**
     * 目录标识
     */
    @LogField
    @ApiModelProperty(value = "删除标识")
    @FieldRemark(column = "delete_flag", field = "delete_flag", name = "删除标识")
    @Column(name = "delete_flag")
    private boolean deleteFlag;

    /**
     * 上传对象
     */
    @ApiModelProperty(value = "模板文件上传使用")
    @Transient
    private MultipartFile file;

    /**
     * 对象大小，包含大小及单位。VUE前端查询时使用
     */
    @ApiModelProperty(value = "对象大小")
    @Transient
    private Capacity fileSize;

    /**
     * 无参构造函数，mybatis会用到
     */
    public ObjectDto() {

    }
    
    public ObjectDto(String id, String objectName, long objectSize, String prefix, String bucketName,
                     boolean isDirectory, boolean deleteFlag, MultipartFile file, Capacity fileSize) {
        this.id = id;
        this.objectName = objectName;
        this.objectSize = objectSize;
        this.prefix = prefix;
        this.bucketName = bucketName;
        this.isDirectory = isDirectory;
        this.deleteFlag = deleteFlag;
        this.file = file;
        this.fileSize = fileSize;
    }

    public String getId() {
        return id;
    }

    public String getObjectName() {
        return objectName;
    }

    public long getObjectSize() {
        return objectSize;
    }

    public String getPrefix() {
        return prefix;
    }

    public String getBucketName() {
        return bucketName;
    }

    public boolean isDirectory() {
        return isDirectory;
    }

    public boolean isDeleteFlag() {
        return deleteFlag;
    }

    public MultipartFile getFile() {
        return file;
    }

    public Capacity getFileSize() {
        return fileSize;
    }

    public void setId(String id) {
        this.id = id;
    }

    public void setObjectName(String objectName) {
        this.objectName = objectName;
    }

    public void setObjectSize(long objectSize) {
        this.objectSize = objectSize;
    }

    public void setPrefix(String prefix) {
        this.prefix = prefix;
    }

    public void setBucketName(String bucketName) {
        this.bucketName = bucketName;
    }

    public void setDirectory(boolean directory) {
        isDirectory = directory;
    }

    public void setDeleteFlag(boolean deleteFlag) {
        this.deleteFlag = deleteFlag;
    }

    public void setFile(MultipartFile file) {
        this.file = file;
    }


    public void setFileSize(Capacity fileSize) {
        this.fileSize = fileSize;
    }

    @Override
    public String getLogFormName() {
        if (StringUtils.isEmpty(super.logFormName)) {
            return "对象管理";
        } else {
            return super.logFormName;
        }
    }

    @Override
    public String getLogTitle() {
        if (StringUtils.isEmpty(super.logTitle)) {
            return "对象";
        } else {
            return super.logTitle;
        }
    }

    public static Builder builder() {
        return new Builder();
    }

    public static final class Builder {
        String id;
        String objectName;
        long objectSize;
        String prefix;
        String bucketName;
        boolean isDirectory;
        boolean deleteFlag;
        MultipartFile file;
        Capacity fileSize;

        public Builder() {
        }

        public Builder id(String id) {
            this.id = id;
            return this;
        }

        public Builder objectName(String objectName) {
            this.objectName = objectName;
            return this;
        }

        public Builder objectSize(long objectSize) {
            this.objectSize = objectSize;
            return this;
        }

        public Builder prefix(String prefix) {
            this.prefix = prefix;
            return this;
        }

        public Builder bucketName(String bucketName) {
            this.bucketName = bucketName;
            return this;
        }

        public Builder isDirectory(boolean isDirectory) {
            this.isDirectory = isDirectory;
            return this;
        }

        public Builder deleteFlag(boolean deleteFlag) {
            this.deleteFlag = deleteFlag;
            return this;
        }

        public Builder file(MultipartFile file) {
            this.file = file;
            return this;
        }

        public Builder fileSize(Capacity fileSize) {
            this.fileSize = fileSize;
            return this;
        }

        public ObjectDto build() {
            return new ObjectDto(id, objectName, objectSize, prefix, bucketName, isDirectory, deleteFlag, file, fileSize);
        }
    }
}
